/*
package yz.com.javautil.test;

import com.googlecode.aviator.runtime.function.FunctionUtils;
import com.googlecode.aviator.runtime.type.AviatorFunction;
import com.googlecode.aviator.runtime.type.AviatorObject;
import com.googlecode.aviator.runtime.type.AviatorString;

import java.util.Iterator;
import java.util.Map;

*/
/**
 * @author liuxk
 * @since 2021-06-18
 * 自定义SQL表达式函数
 *//*

public class ParseSqlFunction implements AviatorFunction {

    @Override
    public AviatorObject call(Map<String, Object> env) {
        return new AviatorString("");
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1) {
        String expression = FunctionUtils.getStringValue(arg1, env);
        if (expression == null || "".equals(expression)) {
            return new AviatorString("");
        }
        // 如果表达式中不包含变量，例如${name}则直接返回该表达式
        if (expression.indexOf("${") < 0) {
            return new AviatorString(expression);
        }

        // 表达式中含有变量${name}时，将变量替换为env中对应的值
        boolean isEmpty = true;
        Iterator<String> it = env.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next();
            String param = "${" + key + "}";

            if (expression.indexOf(param) >= 0 && env.get(key) != null) {
                isEmpty = false;
                expression = expression.replace(param, env.get(key).toString());
            }
        }
        // 当env中不包含变量${name}对应的值时，则表达式中仍包含有字符${name}，此时代表${name}对应的输入框的值为空
        if (expression.indexOf("${") >= 0) {
            return new AviatorString("");
        }

        if (isEmpty) {
            return new AviatorString("");
        } else {
            return new AviatorString(expression);
        }
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2) {
        String expression1 = FunctionUtils.getStringValue(arg1, env);
        String expression2 = FunctionUtils.getStringValue(arg2, env);

        if (expression1 == null || "".equals(expression1)) {
            if (expression2 == null || "".equals(expression2)) {
                return new AviatorString("");
            } else {
                return new AviatorString(" " + expression2 + " ");
            }
        } else {
            return new AviatorString(" " + expression1 + " ");
        }
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1, AviatorObject arg2, AviatorObject arg3) {
        String expression1 = FunctionUtils.getStringValue(arg1, env);
        String connector = FunctionUtils.getStringValue(arg2, env);
        String expression2 = FunctionUtils.getStringValue(arg3, env);

        if (expression1 == null || "".equals(expression1)) {
            if (expression2 == null || "".equals(expression2)) {
                return new AviatorString("");
            } else {
                return new AviatorString(" " + expression2 + " ");
            }
        } else {
            if (expression2 == null || "".equals(expression2)) {
                return new AviatorString(" " + expression1 + " ");
            } else {
                return new AviatorString(" " + expression1 + " " + connector + " " + expression2 + " ");
            }
        }
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4) {
        String expression1 = FunctionUtils.getStringValue(arg1, env);
        String expression2 = FunctionUtils.getStringValue(arg2, env);

        // 当其中有一个表达式为空时，则返回一个空的对象
        if (expression1 == null || expression2 == null) {
            return new AviatorString("");
        } else {
            expression1 = FunctionUtils.getStringValue(call(env, arg1), env);
            expression2 = FunctionUtils.getStringValue(call(env, arg2), env);

            if (expression1.equals(expression2)) {
                return call(env, arg3);
            } else {
                return call(env, arg4);
            }
        }
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5) {
        return call(env, call(env, arg1, arg2, arg3), arg4, arg5);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6) {
        return call(env, arg1, arg2, arg3, arg4, arg5);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7) {
        return call(env, call(env, arg1, arg2, arg3, arg4, arg5), arg6, arg7);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8) {
        return call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9) {
        return call(env, call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7), arg8, arg9);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10) {
        return call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11) {
        return call(env, call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9), arg10, arg11);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11, AviatorObject arg12) {
        return call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11, AviatorObject arg12, AviatorObject arg13) {
        return call(env, call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11), arg12, arg13);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11, AviatorObject arg12, AviatorObject arg13,
                              AviatorObject arg14) {
        return call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11, AviatorObject arg12, AviatorObject arg13,
                              AviatorObject arg14, AviatorObject arg15) {
        return call(env, call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13), arg14, arg15);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11, AviatorObject arg12, AviatorObject arg13,
                              AviatorObject arg14, AviatorObject arg15, AviatorObject arg16) {
        return call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11, AviatorObject arg12, AviatorObject arg13,
                              AviatorObject arg14, AviatorObject arg15, AviatorObject arg16,
                              AviatorObject arg17) {
        return call(env, call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15), arg16, arg17);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11, AviatorObject arg12, AviatorObject arg13,
                              AviatorObject arg14, AviatorObject arg15, AviatorObject arg16,
                              AviatorObject arg17, AviatorObject arg18) {
        return call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11, AviatorObject arg12, AviatorObject arg13,
                              AviatorObject arg14, AviatorObject arg15, AviatorObject arg16,
                              AviatorObject arg17, AviatorObject arg18, AviatorObject arg19) {
        return call(env, call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17), arg18, arg19);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11, AviatorObject arg12, AviatorObject arg13,
                              AviatorObject arg14, AviatorObject arg15, AviatorObject arg16,
                              AviatorObject arg17, AviatorObject arg18, AviatorObject arg19,
                              AviatorObject arg20) {
        return call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19);
    }

    @Override
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1,
                              AviatorObject arg2, AviatorObject arg3, AviatorObject arg4,
                              AviatorObject arg5, AviatorObject arg6, AviatorObject arg7,
                              AviatorObject arg8, AviatorObject arg9, AviatorObject arg10,
                              AviatorObject arg11, AviatorObject arg12, AviatorObject arg13,
                              AviatorObject arg14, AviatorObject arg15, AviatorObject arg16,
                              AviatorObject arg17, AviatorObject arg18, AviatorObject arg19,
                              AviatorObject arg20, AviatorObject... arg21) {
        AviatorObject arg = call(env, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19);

        System.out.println("arg21.length > " + arg21.length);

        int argsLen = arg21.length + 1;
        AviatorObject[] args = new AviatorObject[argsLen];
        args[0] = arg20;

        for (int i = 1; i < argsLen; i++) {
            args[i] = arg21[i];
        }

        if (argsLen % 2 == 0) {
            for (int i = 0; i < argsLen; i = i + 2) {
                if (i == (argsLen - 1)) {
                    arg = call(env, arg, new AviatorString(" "), args[i]);
                } else {
                    arg = call(env, arg, args[i], args[i + 1]);
                }
                arg = call(env, arg, args[i], args[i + 1]);
            }
        } else {
            for (int i = 0; i < argsLen; i = i + 2) {
                arg = call(env, arg, args[i], args[i + 1]);
            }
        }

        return arg;
    }

    @Override
    public String getName() {
        return "parseSql";
    }

}
*/
